package com.example.demo.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.example.demo.po.Find;
import com.example.demo.service.FindService;

@Controller
@RequestMapping("/admin")
public class AdminFindController {
	
	@Autowired	
	private FindService findService;
	
	@RequestMapping(value="/adminFind.action",method=RequestMethod.GET)
	public String indext(Model model){
		
		List<Find> findList = findService.selectAll();
		
		model.addAttribute("findList", findList); 
		
		return "admin/find/findList";
		
	}
	
	@RequestMapping(value="/toEditFind.action",method=RequestMethod.GET)
	public String toEdit(Model model,Integer id){
		
		if(id!=null){
			
			Find find=findService.selectById(id);
			
			model.addAttribute("find", find);
		}
		
		return "admin/find/edit";
		
	}
	
	@RequestMapping(value="/editFind.action",method=RequestMethod.POST)
	public String edit(Find find){
		
		if(find.getId()!=null){
			findService.update(find);
		}else{
			findService.insert(find);
		}
		
		return "redirect:adminFind.action";		
	}
	
	@RequestMapping(value="/deleteFind.action",method=RequestMethod.GET)
	public String delete(Integer id){
		
		findService.delete(id);
		return "redirect:adminFind.action";
		
	}

}
